﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Microsoft.ApplicationServer.Caching.AdminApi;

namespace MDCAdminTool
{
	public abstract class GroupBase : INotifyPropertyChanged, ICacheCommand
	{
		public event PropertyChangedEventHandler PropertyChanged;

		protected void OnPropertyChanged(string property)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(property));
		}

		public CacheCluster Cluster { get; set; }
		public void Start()
		{
			Cluster.Start();
		}

		public void Stop()
		{
			Cluster.Stop();
		}

		public void Restart()
		{
			Cluster.Restart();
		}

		public void Reload()
		{
			Cluster.Reload();
		}

		public CacheStats LoadStatistics()
		{
			return Cluster.LoadStatistics();
		}

		public void Add(CacheEntityBase name)
		{
			Cluster.Add(name);
		}

		public void Remove(CacheEntityBase name)
		{
			Cluster.Remove(name);
		}

		public void LoadChildren()
		{
			Cluster.LoadChildren();
		}

		public void LoadConfig()
		{
			Cluster.LoadConfig();
		}

		public void SaveConfig()
		{
			Cluster.SaveConfig();
		}

		public string Name { get; set; }

		public CacheType Type { get; set; }

		public ServiceStatus Status { get; set; }
	}

	public class CacheGroup : GroupBase
	{
        private ObservableCollection<MdcCache> _cacheNames = new ObservableCollection<MdcCache>();

        public ObservableCollection<MdcCache> CacheNames
		{
			get { return _cacheNames; }
			set { _cacheNames = value; OnPropertyChanged("CacheNames"); }
		}
	}

    public class CacheGroupHA : GroupBase
    {
        private ObservableCollection<MdcCache> _cacheNames = new ObservableCollection<MdcCache>();

        public ObservableCollection<MdcCache> CacheNames
        {
            get { return _cacheNames; }
            set { _cacheNames = value; OnPropertyChanged("CacheNames"); }
        }
    }

}